"""
Test for the Room Type Classes
"""


#from datetime import datetime
import datetime

#Python Module Imports
import sqlalchemy.exc


import json
import cogentviewer.models as models
import cogentviewer.tests.base as base



class TestSensorType(base.ModelTestCase):
    def _serialobj(self):
        """Helper Method to provde an object to serialise"""
        theItem = models.SensorType(id=1,
                                    name="Temperature",
                                    code="T",
                                    units = "DegC",
                                    c0 = 0,
                                    c1 = 1,
                                    c2 = 0,
                                    c3 = 1)

        return theItem
                                  
    def _dictobj(self):
        """Helper method to provide a dictionay representaiton of the object generated by 
        _serialobj()"""

        theDict = {"__table__":"SensorType",
                   "id":1,
                   "name":"Temperature",
                   "code":"T",
                   "units" : "DegC",
                   "c0" : 0,
                   "c1" : 1,
                   "c2" : 0,
                   "c3" : 1}
        return theDict


    def testEq(self):
        """Test for Equality"""
        #Test Equality
        item1 = models.SensorType(id=1,
                                  name="Temperture",
                                  code="T",
                                  units = "DegC",
                                  c0 = 0,
                                  c1 = 1,
                                  c2 = 0,
                                  c3 = 1)

        item2 = models.SensorType(id=1,
                                  name="Temperture",
                                  code="T",
                                  units = "DegC",
                                  c0 = 0,
                                  c1 = 1,
                                  c2 = 0,
                                  c3 = 1)

        self.assertEqual(item1,item2)
        self.assertReallyEqual(item1,item2)


        #Neither the C0,C1... 
        item2.c0 = 1
        item2.c2 = 1

        self.assertEqual(item1,item2)
        self.assertReallyEqual(item1,item2)


    def testNEQ(self):
        item1 = models.SensorType(id=1,
                                  name="Temperture",
                                  code="T",
                                  units = "DegC",
                                  c0 = 0,
                                  c1 = 1,
                                  c2 = 0,
                                  c3 = 1)

        item2 = models.SensorType(id=1,
                                  name="Temperture",
                                  code="T",
                                  units = "DegC",
                                  c0 = 0,
                                  c1 = 1,
                                  c2 = 0,
                                  c3 = 1)

        self.assertEqual(item1,item2)
    
        item2.id = 2
        self.assertNotEqual(item1,item2)
        self.assertReallyNotEqual(item1,item2)
        

        item2.id = 1
        item2.name = "FOO"
        self.assertNotEqual(item1,item2)
        self.assertReallyNotEqual(item1,item2)

        item2.name = "Temperature"
        item2.code = "C"

        self.assertNotEqual(item1,item2)
        self.assertReallyNotEqual(item1,item2)

        item2.code = "T"
        item2.units = "PPM"

        self.assertNotEqual(item1,item2)
        self.assertReallyNotEqual(item1,item2)

    

    def testCmp(self):

        item1 = models.SensorType(id=1,
                                  name="Temperture",
                                  code="T",
                                  units = "DegC",
                                  c0 = 0,
                                  c1 = 1,
                                  c2 = 0,
                                  c3 = 1)

        item2 = models.SensorType(id=1,
                                  name="Temperture",
                                  code="T",
                                  units = "DegC",
                                  c0 = 0,
                                  c1 = 1,
                                  c2 = 0,
                                  c3 = 1)

        self.assertEqual(item1,item2)

        #CMP on Id
        item2.name = "A_Temperature"
        self.assertGreater(item1,item2)

        item2.name = "Z_Temperature"
        self.assertLess(item1,item2)
        
